<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript"
	src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="./js/jquery.qrcode.min.js"></script>
<!-- 中文转码 -->
<script type="text/javascript">
	function qcodetochar(str) {
		var out, i, len, c;
		out = "";
		len = str.length;
		for (i = 0; i < len; i++) {
			c = str.charCodeAt(i);
			if ((c >= 0x0001) && (c <= 0x007F)) {
				out += str.charAt(i);
			} else if (c > 0x07FF) {
				out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
				out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
				out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
			} else {
				out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
				out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
			}
		}
		return out;
	};
</script>
<script type="text/javascript">
	window.onload = function() {
	}
</script>
<title>hello</title>
</head>
<body>
	<%
		String ipString = (String) request.getAttribute("IP");
		String musicListString = (String) request.getAttribute("musicList");
	%>
	<!--  <audio autoplay="autoplay" controls="controls" loop="loop"
		preload="auto" src="./audio/曾轶可 - 旅行的意义.mp3"> 你的浏览器不支持audio标签
	</audio>-->
	<script type="text/javascript">
		var musicIndex = 0;
		var musicList = eval(<%=musicListString%>);
		var musicCount = musicList.length;
		if (0 < musicCount) {
			var musicName = document.createElement("h2");
			var audio = document.createElement("audio");
			var musicItem = musicList[musicIndex];
			musicName.innerText = musicItem.substring(musicItem
					.lastIndexOf("/") + 1, musicItem.length);
			audio.src = '.' + musicItem;
			audio.controls = true;
			// audio.loop = true;
			audio.addEventListener('ended', function() {
				musicIndex++;
				if (musicIndex == musicCount) {
					musicIndex = 0;
				}
				musicItem = musicList[musicIndex];
				musicName.innerText = musicItem.substring(musicItem
						.lastIndexOf("/") + 1, musicItem.length);
				audio.src = '.' + musicItem;
				audio.play();
			}, false);
			document.body.appendChild(musicName);
			document.body.appendChild(audio);
			audio.play();
		}
		document.body.appendChild(document.createElement("p"));
		var ip = "<%=ipString%>";
		var ipTag = document.createElement("h2");
		ipTag.innerText = ip;
		document.body.appendChild(ipTag);
		var qr = document.createElement("div");
		document.body.appendChild(qr);
		$(qr).qrcode({
			"render" : "div",
			"size" : 100,
			"color" : "#3a3",
			"text" : ip
		});
	</script>
</body>
</html>